package com.aaa.product.service.impl;

import com.aaa.product.dao.TbPrdExtendMapper;
import com.aaa.product.entity.TbPrdExtend;
import com.aaa.product.service.TbPrdExtendService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aaa.product.entity.TbPrdInfo;
import com.aaa.product.dao.TbPrdInfoMapper;
import com.aaa.product.service.TbPrdInfoService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TbPrdInfoServiceImpl extends ServiceImpl<TbPrdInfoMapper, TbPrdInfo> implements TbPrdInfoService{

    @Resource
    TbPrdInfoMapper tbPrdInfoMapper;
    @Resource
    TbPrdExtendMapper tbPrdExtendMapper;


    public TbPrdInfo findById(String tid) {
        return tbPrdInfoMapper.selectById(tid);
    }

    public List<TbPrdInfo> listByLname(String labelName) {
        QueryWrapper<TbPrdInfo> travelsQueryWrapper = new QueryWrapper<>();
        travelsQueryWrapper.like("label_name", labelName);
        return this.list(travelsQueryWrapper);
    }

    public boolean subtractStore2(String tid, Integer store) {
        return tbPrdInfoMapper.subtractStore2(tid,store);
    }

    public boolean addStore(String tid, Integer store) {
        return tbPrdInfoMapper.addStore(tid,store);

    }

    public TbPrdInfo compareStore(String tid, Integer store) {
        return tbPrdInfoMapper.compareStore(tid,store);
    }

    public List<TbPrdInfo> listDesc() {
        QueryWrapper<TbPrdInfo> tbPrdInfoQueryWrapper = new QueryWrapper<>();
        tbPrdInfoQueryWrapper.orderByDesc("update_date");
        return this.list(tbPrdInfoQueryWrapper);
    }

    /**
     * 查询活动里面未添加的商品
     *
     * @param arr
     * @return
     */
    @Override
    public List<TbPrdInfo> queryTbPrdInfoByArr(String[] arr) {
        QueryWrapper<TbPrdInfo> wrapper = new QueryWrapper<>();
        for (String s : arr) {
            wrapper.ne("tid",s);
        }
        wrapper.ge("store",100);
//        List<TbPrdInfo> list = list(wrapper);
        List<TbPrdInfo> list = this.list(wrapper);
        for (TbPrdInfo tbPrdInfo : list) {
            TbPrdExtend tbPrdExtend = tbPrdExtendMapper.getTbPrdExtend(tbPrdInfo.getTid());
            tbPrdInfo.setTbPrdExtend(tbPrdExtend);
            /*if(tbPrdInfo.getStore() < 100){
                list.remove(tbPrdInfo);
            }*/
        }

        return list;
    }

}
